/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gestionnaires;

import java.util.ArrayList;
import java.util.Collection;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import modeles.Commentaire;
import modeles.Note;
import modeles.Utilisateur;

/**
 *
 * @author Christian
 */
@Stateless
public class GestionnaireUtilisateurs {

    @EJB
    private GestionnaireCommentaires gestionnaireCommentaires;
    @EJB
    private GestionnaireNotes gestionnaireNotes;
    @PersistenceContext
    private EntityManager em;

    public void creeUtilisateursDeTest() {
        Utilisateur u = new Utilisateur("parturient.montes.nascetur@temporest.edu", "FAD46DAY1EJ", "Arthur", "Melodie", "Ap #690-7469 Nulla Ave", "77000", "Pullman", "9155506717");
        em.persist(u);
        u = new Utilisateur("dui@necmollisvitae.org", "AKC00YTU6NN", "Gavin", "Kasper", "P.O. Box 589 5683 Rutrum Road", "80196", "Turlock", "1418335375");
        em.persist(u);
        u = new Utilisateur("elit.a@gravidasagittis.org", "ERD51RZL2OH", "Derek", "Merrill", "Ap #339-3899 Mauris Avenue", "60705", "Anderson", "8146752824");
        em.persist(u);
        u = new Utilisateur("enim.diam@neque.ca", "HYE55JNE6XW", "Nero", "Macon", "Ap #754-4493 Quisque Street", "03166", "Alamogordo", "8043181473");
        em.persist(u);
        u = new Utilisateur("ligula.consectetuer.rhoncus@Proinvelnisl.org", "JLJ00HJS0VT", "Garth", "Wylie", "2724 Malesuada St.", "03512", "Rolling Hills Estates", "6916281725");
        em.persist(u);
        u = new Utilisateur("sit@sodalesnisi.org", "IMM08LMX4TZ", "Reed", "Ferdinand", "P.O. Box 782 9553 Sagittis. St.", "13204", "Asheville", "3025662917");
        em.persist(u);
        u = new Utilisateur("urna@molestie.ca", "OHX35BKR8JW", "Camden", "Lesley", "Ap #239-6593 Sem Rd.", "87259", "El Monte", "7637886315");
        em.persist(u);
        u = new Utilisateur("neque.Morbi.quis@nullaat.com", "KNG51EFT3WO", "Ahmed", "Cedric", "782-5997 Nisi. Avenue", "74360", "Saint Cloud", "7654278620");
        em.persist(u);
        u = new Utilisateur("et@dui.edu", "NIQ55SNY4CS", "Vincent", "Joy", "130-6777 Feugiat St.", "84952", "Miami", "7371521157");
        em.persist(u);
        u = new Utilisateur("Sed.nunc.est@aaliquet.edu", "ZHT97BYB1QW", "Keegan", "Kelly", "P.O. Box 192 2223 Vivamus Av.", "81712", "Tuscaloosa", "7058578406");
        em.persist(u);
        u = new Utilisateur("sem.mollis@iaculisaliquetdiam.ca", "VZS45BHP1MN", "Elvis", "Dylan", "P.O. Box 442 6664 Penatibus Rd.", "72151", "Peru", "5713541348");
        em.persist(u);
        u = new Utilisateur("non.vestibulum.nec@urnaUttincidunt.org", "CNC47TAZ1RT", "Evan", "Sybil", "Ap #799-2457 Dictum Rd.", "60712", "Bismarck", "6086081032");
        em.persist(u);
        u = new Utilisateur("lorem.semper@nibh.edu", "DFY40EYQ9FI", "Amos", "Vladimir", "P.O. Box 182 3979 Aliquet Street", "86378", "Lancaster", "2194145364");
        em.persist(u);
        u = new Utilisateur("velit.egestas.lacinia@pellentesquetellus.com", "PZS69FYZ3JW", "Yoshio", "Pearl", "P.O. Box 803 169 At Av.", "11166", "Malibu", "4131814412");
        em.persist(u);
        u = new Utilisateur("morbi@liberomauris.edu", "SKW61MOJ2OO", "Hall", "Penelope", "618-2899 Diam St.", "66171", "Mason City", "9369760408");
        em.persist(u);
        u = new Utilisateur("sem@etultrices.org", "RHE00LFI0MY", "Mark", "Leah", "P.O. Box 660 1592 Vel Av.", "75945", "Homer", "5457833555");
        em.persist(u);
        u = new Utilisateur("vel.faucibus@elit.ca", "AGW68PMZ2QS", "Reuben", "Kiara", "6859 Non Road", "85478", "South Burlington", "3448046949");
        em.persist(u);
        u = new Utilisateur("lorem.vitae.odio@ametfaucibusut.org", "SRG44UPX7GU", "Craig", "Odessa", "Ap #824-4646 Sed St.", "96443", "LaGrange", "8231976648");
        em.persist(u);
        u = new Utilisateur("dolor@Vivamusrhoncus.ca", "KZP66DRG9DG", "Lance", "Mara", "P.O. Box 611 1411 Ridiculus Avenue", "45022", "Salisbury", "6086753159");
        em.persist(u);
        u = new Utilisateur("mollis.Duis.sit@est.com", "BPT62KPI9ST", "Keefe", "Ronan", "Ap #638-8652 Fermentum Av.", "41605", "Rancho Santa Margarita", "6548693650");
        em.persist(u);
        u = new Utilisateur("blandit.congue@Aliquamtincidunt.edu", "MQV04UWB3SN", "John", "Felicia", "P.O. Box 313 5800 Nulla. St.", "51144", "Superior", "1527018576");
        em.persist(u);
        u = new Utilisateur("Fusce.fermentum@duiquis.com", "TEU24KJO6YC", "Orlando", "Buckminster", "P.O. Box 621 7458 Magna. St.", "23731", "Grafton", "2794146954");
        em.persist(u);
        u = new Utilisateur("a@nonenimcommodo.org", "MNS26HKR8EX", "Cedric", "Wendy", "456-690 Molestie. Street", "27263", "Broken Arrow", "3833689136");
        em.persist(u);
        u = new Utilisateur("et@scelerisqueduiSuspendisse.org", "UXP98WHD2JK", "Abdul", "Knox", "Ap #376-2185 Eu Road", "96885", "Williamsburg", "3233100996");
        em.persist(u);
        u = new Utilisateur("elit.Etiam.laoreet@dictumplacerat.ca", "SPI71JCV6IV", "Eaton", "Channing", "P.O. Box 970 1438 Pellentesque Avenue", "42353", "Fall River", "5923441114");
        em.persist(u);
        u = new Utilisateur("per.inceptos.hymenaeos@velmaurisInteger.edu", "NHX84PTQ5WC", "Solomon", "Charde", "125-1267 In St.", "72524", "Odessa", "3846746275");
        em.persist(u);
        u = new Utilisateur("lobortis@netus.ca", "USX69MVJ5YC", "Preston", "Jena", "P.O. Box 662 1032 Lectus St.", "62808", "Brigham City", "8421708477");
        em.persist(u);
        u = new Utilisateur("est@hendrerit.edu", "TXE53MSN0VD", "Duncan", "Maxwell", "254 Risus. St.", "69030", "Sun Valley", "8861589658");
        em.persist(u);
        u = new Utilisateur("magna.Sed.eu@Sed.ca", "UJR96ICW0DO", "Arden", "Camilla", "P.O. Box 854 9583 Nunc St.", "68548", "Brown Deer", "1782010756");
        em.persist(u);
        u = new Utilisateur("at.sem.molestie@mi.edu", "CYP10NGC3FT", "Colton", "Nina", "3254 Diam St.", "87588", "Mesa", "6323520530");
        em.persist(u);
        u = new Utilisateur("nisi@parturient.org", "FBX92QEJ4NE", "Carlos", "Alana", "Ap #617-4350 Imperdiet St.", "88909", "Maywood", "4968035245");
        em.persist(u);
        u = new Utilisateur("orci@Nulla.edu", "PXF79FVM7GI", "Logan", "Cooper", "8124 Semper Rd.", "54668", "Erie", "8271994053");
        em.persist(u);
        u = new Utilisateur("libero@a.edu", "VFJ18PNL3JZ", "Rahim", "Alika", "543-8454 Proin Rd.", "05700", "San Bernardino", "5408749562");
        em.persist(u);
        u = new Utilisateur("purus.Duis.elementum@egetdictumplacerat.ca", "FPW06MQY9MA", "Kaseem", "David", "P.O. Box 628 1051 Nunc Rd.", "04843", "Kenosha", "1615544703");
        em.persist(u);
        u = new Utilisateur("dis.parturient.montes@Namporttitorscelerisque.org", "TWP30RYD2BE", "Marsden", "Ursa", "763-6855 Pede. St.", "52297", "Wilson", "9076812698");
        em.persist(u);
        u = new Utilisateur("arcu.Aliquam.ultrices@lacusvarius.edu", "SYJ38AKG7CU", "Amir", "Flavia", "744-8252 Velit Av.", "03615", "Egg Harbor", "2313804508");
        em.persist(u);
        u = new Utilisateur("semper.erat.in@Namporttitorscelerisque.edu", "QMY68RLC4HE", "Omar", "Vanna", "P.O. Box 565 6423 Pellentesque Street", "37442", "Bakersfield", "5004945585");
        em.persist(u);
        u = new Utilisateur("semper@lacus.ca", "PYZ38IPB8GL", "Leonard", "Olivia", "4116 Enim. Av.", "97881", "Hampton", "4086803662");
        em.persist(u);
        u = new Utilisateur("aliquet.nec@feugiat.org", "EUV64ONH3YF", "Brent", "Otto", "P.O. Box 530 4305 Morbi Street", "91204", "Springfield", "7646742920");
        em.persist(u);
        u = new Utilisateur("dolor.dolor@sempercursus.ca", "YAC07EKW6VV", "Phelan", "Armando", "5164 Eu St.", "83168", "Highland Park", "5041601501");
        em.persist(u);
        u = new Utilisateur("nunc.est.mollis@turpisegestasAliquam.org", "UNJ52LLL3YH", "Omar", "Bianca", "510-5738 Semper Rd.", "95207", "San Rafael", "1942836680");
        em.persist(u);
        u = new Utilisateur("est@penatibuset.org", "UQW57TBF2QE", "Prescott", "Sonya", "Ap #286-4601 Augue Rd.", "13349", "White Plains", "3024489258");
        em.persist(u);
        u = new Utilisateur("velit.Cras.lorem@semPellentesque.com", "ULQ53VCZ0OD", "Forrest", "Sonia", "9090 Magna Road", "30389", "Fayetteville", "1418766140");
        em.persist(u);
        u = new Utilisateur("dapibus.quam.quis@velfaucibus.edu", "JQR50OCJ3AT", "Harrison", "Garrett", "Ap #652-8281 Eros Road", "74540", "Pine Bluff", "9051411878");
        em.persist(u);
        u = new Utilisateur("a.nunc@rutrumurna.edu", "UNY28NPM1LG", "Jordan", "Wendy", "Ap #666-6651 Velit. Rd.", "16137", "Appleton", "1649091840");
        em.persist(u);
        u = new Utilisateur("tincidunt@tinciduntdui.ca", "SBA29SUQ3MV", "Walter", "Lysandra", "Ap #306-3558 Feugiat Ave", "01392", "Chicopee", "4316884584");
        em.persist(u);
        u = new Utilisateur("turpis.egestas.Aliquam@pretium.org", "LCI36LDI6MK", "Rigel", "Serina", "P.O. Box 769 3958 Felis St.", "14208", "Springfield", "8267322835");
        em.persist(u);
        u = new Utilisateur("senectus@aliquetdiamSed.com", "QVU46EOS9YX", "Dustin", "Clark", "P.O. Box 779 4110 Euismod St.", "74706", "Newport", "4285228806");
        em.persist(u);
        u = new Utilisateur("tempus@turpisegestasAliquam.com", "SUI09FEB9PU", "Henry", "Haley", "P.O. Box 267 3675 Risus. St.", "86505", "Idaho Springs", "2179953736");
        em.persist(u);
        u = new Utilisateur("lacinia.vitae.sodales@utdolordapibus.com", "XNE38ZMW1VT", "Rahim", "Hilary", "9804 Ultrices Street", "45841", "Downey", "2499888273");
        em.persist(u);
        u = new Utilisateur("turpis.egestas@eu.org", "BMK82UQO6PA", "Brock", "Joy", "Ap #644-7152 Purus. Street", "64553", "Quincy", "3613848892");
        em.persist(u);
        u = new Utilisateur("ipsum.Phasellus.vitae@feugiat.ca", "QXU74GAE8SV", "Emmanuel", "Declan", "5617 Et Rd.", "20805", "Plattsburgh", "9496699368");
        em.persist(u);
        u = new Utilisateur("placerat@massa.com", "LGD25JPF3DM", "Herrod", "Adena", "Ap #564-4264 Ut Avenue", "61060", "Knoxville", "3966200621");
        em.persist(u);
        u = new Utilisateur("nulla.Integer.vulputate@ultriciesligula.edu", "YRP37EJK6UC", "Rudyard", "Scarlet", "988-8641 Luctus Avenue", "96096", "Rosemead", "3872422398");
        em.persist(u);
        u = new Utilisateur("Cras.dolor.dolor@habitant.edu", "SVD56WMZ8IX", "Isaiah", "Idona", "P.O. Box 206 147 Sed St.", "82415", "Rancho Santa Margarita", "1347357139");
        em.persist(u);
        u = new Utilisateur("Etiam.vestibulum@vulputateullamcorpermagna.ca", "QLW18THB8HY", "Boris", "Moses", "235-9869 Integer Rd.", "88336", "Laramie", "7517227966");
        em.persist(u);
        u = new Utilisateur("eget@Nunclectus.org", "FPO32QYR7YO", "Levi", "Ezra", "6405 Ut Street", "79301", "Bridgeport", "9871403029");
        em.persist(u);
        u = new Utilisateur("amet.nulla@augue.org", "WZM45UIV5ZQ", "Jerry", "Gisela", "723-5772 Ultrices. Ave", "17920", "Ardmore", "5962177071");
        em.persist(u);
        u = new Utilisateur("ultricies.dignissim@Pellentesque.edu", "PUV11NVQ1KU", "Upton", "Hedwig", "648-9854 Et Avenue", "07184", "Danville", "6669651239");
        em.persist(u);
        u = new Utilisateur("nisi.magna@Inmi.edu", "QPX59YOK5OL", "Elton", "Noelani", "8541 In Av.", "46711", "Tucson", "4487929095");
        em.persist(u);
        u = new Utilisateur("egestas.hendrerit.neque@Nullamscelerisque.edu", "ZLP47HSO2OA", "Slade", "Gary", "P.O. Box 551 4600 Dolor St.", "02332", "Healdsburg", "3727318354");
        em.persist(u);
        u = new Utilisateur("pede.ultrices.a@lectusrutrumurna.ca", "YBW83ZVQ4HS", "Omar", "Marny", "P.O. Box 434 7711 Donec Avenue", "21149", "Las Cruces", "9323071080");
        em.persist(u);
        u = new Utilisateur("dui.nec.urna@lacusEtiambibendum.ca", "LYP15REP0YX", "Charles", "April", "Ap #384-5181 Natoque St.", "86557", "New Kensington", "4746714100");
        em.persist(u);
        u = new Utilisateur("Proin.non@luctusCurabituregestas.edu", "VMC05KEC7RX", "Ferdinand", "Doris", "8640 Nisi St.", "83464", "West Valley City", "8503187362");
        em.persist(u);
        u = new Utilisateur("sociis.natoque@iaculislacuspede.ca", "WPM79UFB6CY", "Addison", "Kyle", "Ap #485-9885 Cursus Rd.", "56134", "Jeffersonville", "9686464329");
        em.persist(u);
        u = new Utilisateur("augue@auctornonfeugiat.edu", "JKE39UWM2WA", "Slade", "Yardley", "449-9870 Lacus. Street", "20494", "Sandy Springs", "2484126558");
        em.persist(u);
        u = new Utilisateur("luctus.Curabitur.egestas@tellussem.edu", "URB66LZA8YH", "Steel", "Hope", "P.O. Box 473 7478 Dui Street", "18834", "Hilo", "9235804675");
        em.persist(u);
        u = new Utilisateur("Nullam@Aliquamornarelibero.com", "VGS76YAW3UZ", "Bruno", "Maxwell", "P.O. Box 257 8440 Morbi Rd.", "36740", "Hammond", "2666699426");
        em.persist(u);
        u = new Utilisateur("volutpat@Nuncmauris.org", "YYS06ZRR1NA", "Preston", "Craig", "Ap #660-4984 Arcu. Av.", "21121", "Mequon", "5864480488");
        em.persist(u);
        u = new Utilisateur("augue.porttitor@Maurisnondui.edu", "YTD79OOO1BV", "Fritz", "Cecilia", "Ap #626-4245 Aliquam Rd.", "49930", "Grass Valley", "2886617588");
        em.persist(u);
        u = new Utilisateur("nunc@eumetus.com", "OXF90HMU8XF", "Rudyard", "Reese", "P.O. Box 699 7172 Fringilla Av.", "02319", "Tempe", "9718191783");
        em.persist(u);
        u = new Utilisateur("Fusce.diam@mollisnoncursus.ca", "OZZ37NGY1ZZ", "Harding", "Eve", "P.O. Box 182 1944 Ut Road", "38330", "Beckley", "2472188688");
        em.persist(u);
        u = new Utilisateur("orci@nonfeugiat.org", "OHM95PJU6OD", "Keith", "Troy", "6171 Dictum Rd.", "06715", "North Charleston", "8358981444");
        em.persist(u);
        u = new Utilisateur("sem.eget.massa@gravida.ca", "WFJ97GLK2AM", "Vaughan", "Ray", "542-7636 Venenatis Rd.", "93685", "Bridgeport", "3006154077");
        em.persist(u);
        u = new Utilisateur("mi@massa.ca", "HMK22BRR5LP", "Todd", "Brenden", "P.O. Box 706 5505 Lectus Rd.", "23687", "Philadelphia", "5571619953");
        em.persist(u);
        u = new Utilisateur("tristique@fringillacursus.org", "XHD84OHQ2WX", "Keane", "Kennan", "P.O. Box 324 9142 Urna. Road", "92502", "Lafayette", "6565940871");
        em.persist(u);
        u = new Utilisateur("neque.Sed.eget@euismodindolor.ca", "YVU53MWP7UO", "Alan", "Fiona", "2720 Justo Street", "84779", "Sanford", "6793963761");
        em.persist(u);
        u = new Utilisateur("vulputate.eu@facilisisvitae.edu", "DUV68DGC9NX", "Flynn", "Erica", "P.O. Box 417 9926 Ut Street", "06979", "Port Jervis", "4126636714");
        em.persist(u);
        u = new Utilisateur("mauris.Integer@commodoauctor.edu", "NFZ85REQ0ES", "Nash", "Basia", "8711 Quis Ave", "80444", "Berlin", "2556513565");
        em.persist(u);
        u = new Utilisateur("vestibulum.Mauris@molestie.org", "RGX39AWQ8SL", "Thor", "Catherine", "179-9041 Integer Street", "77490", "Agawam", "6552678398");
        em.persist(u);
        u = new Utilisateur("et.nunc.Quisque@MaurismagnaDuis.org", "PHZ54VVS9TM", "Lyle", "Chandler", "P.O. Box 997 2700 Sed Ave", "71940", "Delta Junction", "5894658278");
        em.persist(u);
        u = new Utilisateur("velit.Cras.lorem@nonmassanon.ca", "QJL25WZS8GL", "Abel", "Bruno", "436-8775 Aliquam St.", "37586", "Rye", "6558218852");
        em.persist(u);
        u = new Utilisateur("Nunc@nibh.ca", "ZIF94DAV5XD", "Daniel", "Imogene", "P.O. Box 595 4046 Leo. Avenue", "74682", "Kansas City", "4454662694");
        em.persist(u);
        u = new Utilisateur("Donec.felis@Crasdolor.com", "COK39IGE8RX", "Dominic", "Devin", "Ap #277-9979 Lacus. Rd.", "26698", "Cypress", "9284846990");
        em.persist(u);
        u = new Utilisateur("odio.auctor@Duiscursus.edu", "GHB55WBG0BN", "Nehru", "Megan", "3621 Orci Rd.", "86771", "Gettysburg", "7131077299");
        em.persist(u);
        u = new Utilisateur("mauris@felisNulla.org", "TGP29GSN1CK", "Raphael", "Regina", "P.O. Box 889 672 Cursus Avenue", "49116", "Idaho Falls", "2676191917");
        em.persist(u);
        u = new Utilisateur("Suspendisse@Suspendissenonleo.org", "CAB88FVY0WL", "Arden", "Alexis", "751-3760 Leo Ave", "13504", "Laconia", "3164160261");
        em.persist(u);
        u = new Utilisateur("in@Aliquamtincidunt.com", "MUW58LGG1QL", "James", "Carolyn", "Ap #797-1597 Gravida Avenue", "31292", "Manchester", "6461854333");
        em.persist(u);
        u = new Utilisateur("a.aliquet.vel@sitametrisus.com", "ZSW48JLN1PV", "Elton", "Tamekah", "434-542 Placerat Rd.", "04869", "Citrus Heights", "9202015084");
        em.persist(u);
        u = new Utilisateur("arcu.Vestibulum@nonleoVivamus.edu", "YNC24WWV2XX", "Mason", "Quintessa", "4747 Eu Rd.", "89690", "Clairton", "9855634839");
        em.persist(u);
        u = new Utilisateur("ipsum.cursus.vestibulum@risusat.com", "FBI17CQI0CF", "Yuli", "Nevada", "1390 Vitae St.", "94658", "Auburn", "4104731161");
        em.persist(u);
        u = new Utilisateur("Suspendisse.ac@Crasegetnisi.com", "GPM45EPP0TO", "Jameson", "Georgia", "527-5198 Integer Road", "48279", "Hayward", "4182035399");
        em.persist(u);
        u = new Utilisateur("magna.et.ipsum@fringilla.edu", "EDS64UBW2OH", "Barrett", "Riley", "P.O. Box 536 2371 Fames St.", "06341", "Olean", "4149381598");
        em.persist(u);
        u = new Utilisateur("ut@quisdiam.com", "XVP06QBV1HV", "Preston", "Luke", "697-1201 Diam Avenue", "76457", "Waco", "5619232228");
        em.persist(u);
        u = new Utilisateur("fringilla@perinceptos.org", "QON41TJL4LD", "Arden", "Tallulah", "2262 Lacinia Av.", "49173", "Kahului", "9522474139");
        em.persist(u);
        u = new Utilisateur("Duis.a@Vivamus.edu", "PUP78MLS3RE", "Dean", "Scarlett", "875-2127 Massa. Rd.", "50634", "Rapid City", "7435576152");
        em.persist(u);
        u = new Utilisateur("erat.Vivamus.nisi@lacusAliquamrutrum.edu", "CAF38DZD9FR", "Adam", "Samuel", "Ap #771-8766 Gravida Rd.", "92469", "New Brunswick", "2255985087");
        em.persist(u);
        u = new Utilisateur("vel.pede@diamvelarcu.ca", "YQO94OKA3GY", "Kenyon", "Nola", "731-7600 Magna. Rd.", "82777", "Sonoma", "6524572437");
        em.persist(u);
        u = new Utilisateur("Sed.pharetra@tempus.ca", "QAU27JTB0NX", "Davis", "Devin", "P.O. Box 310 6310 Venenatis St.", "45117", "Michigan City", "5593861469");
        em.persist(u);
        u = new Utilisateur("lectus.quis.massa@a.com", "JZK62ASI2IT", "Rudyard", "Jaden", "P.O. Box 428 1583 Metus. Rd.", "96068", "Lewiston", "3827162566");
        em.persist(u);
        u = new Utilisateur("toto@toto.fr", "totototo", "TataNom", "TotoPrenom", "P.O. Box 428 1583 Metus. Rd.", "96068", "Lewiston", "3827162566");
        em.persist(u);
        u = new Utilisateur("admin@admin.fr", "totototo", "Michel", "Buffa", "P.O. Box 428 1583 Metus. Rd.", "96068", "Lewiston", "3827162566", true);
        em.persist(u);
    }

    public Utilisateur creeUtilisateur(String email, String password, String nom, String prenom, String adresse, String codePostal, String ville, String telephone) {
        if (password == null || email == null || nom == null || prenom == null
                || adresse == null || codePostal == null || ville == null || telephone == null) {
            return null;
        }
        if (email.isEmpty() || password.isEmpty() || nom.isEmpty() || prenom.isEmpty() || adresse.isEmpty()
                || codePostal.isEmpty() || ville.isEmpty() || telephone.isEmpty()) {
            return null;
        }
        if (getUserByEmail(email) != null) {
            return null;
        }
        Utilisateur u = new Utilisateur(email, password, nom, prenom, adresse, codePostal, ville, telephone);
        em.persist(u);
        return u;
    }

    public Utilisateur modifierInfosUtilisateur(String email, String nom, String prenom, String telephone) {
        if (email == null || nom == null || email.isEmpty() || nom.isEmpty()
                || prenom == null || prenom == null || telephone.isEmpty() || telephone.isEmpty()) {
            return null;
        }
        Utilisateur utilisateur = null;
        if ((utilisateur = getUserByEmail(email)) == null) {
            return null;
        }
        utilisateur.setNom(nom);
        utilisateur.setPrenom(prenom);
        utilisateur.setTelephone(telephone);
        em.merge(utilisateur);
        return utilisateur;
    }

    public Utilisateur modifierAdresse(String email, String adresse, String codePostal, String ville) {
        if (email == null || adresse == null || email.isEmpty() || adresse.isEmpty()
                || codePostal == null || ville == null || codePostal.isEmpty() || ville.isEmpty()) {
            return null;
        }
        Utilisateur utilisateur = null;
        if ((utilisateur = getUserByEmail(email)) == null) {
            return null;
        }
        utilisateur.setAdresse(adresse);
        utilisateur.setCodePostal(codePostal);
        utilisateur.setVille(ville);
        em.merge(utilisateur);
        return utilisateur;
    }

    public Utilisateur modifierEmail(String email, String new_email) {
        if (email == null || new_email == null || email.isEmpty() || new_email.isEmpty()) {
            return null;
        }
        Utilisateur utilisateur = null;
        if ((utilisateur = getUserByEmail(email)) == null || getUserByEmail(new_email) != null) {
            return null;
        }
        utilisateur.setEmail(new_email);
        em.merge(utilisateur);
        return utilisateur;
    }

    public Utilisateur modifierPwd(String email, String new_password) {
        if (email == null || new_password == null || email.isEmpty() || new_password.isEmpty()) {
            return null;
        }
        Utilisateur utilisateur = null;
        if ((utilisateur = getUserByEmail(email)) == null) {
            return null;
        }
        utilisateur.setPassword(new_password);
        em.merge(utilisateur);
        return utilisateur;
    }

    public Collection<Utilisateur> getAllUsers() {
        Query q = em.createQuery("select o from Utilisateur o", Utilisateur.class);
        return q.getResultList();
    }

    public Utilisateur getUserById(int id) {
        Query q = em.createQuery("select o from Utilisateur o where o.id=" + id, Utilisateur.class);
        if (q.getResultList().size() <= 0) {
            return null;
        }
        return (Utilisateur) q.getResultList().get(0);
    }

    public Utilisateur getUserByEmail(String email) {
        if (email == null) {
            return null;
        }
        if (email.isEmpty()) {
            return null;
        }
        Query q = em.createQuery("select o from Utilisateur o where o.email like'" + email + "'", Utilisateur.class);
        if (q.getResultList().size() <= 0) {
            return null;
        }
        return (Utilisateur) q.getResultList().get(0);
    }

    public void suprimeUserByEmail(String email) {
        if (email == null) {
            return;
        }
        if (email.isEmpty()) {
            return;
        }
        Utilisateur utilisateur = getUserByEmail(email);
        if (utilisateur == null) {
            return;
        }
        suprimeUserById(utilisateur.getId());
    }

    public void suprimeUserById(int id) {
        Utilisateur utilisateur = getUserById(id);
        Collection<Commentaire> commentaires = new ArrayList<Commentaire>(gestionnaireCommentaires.getCommentaireByUtilisateur(utilisateur));
        for (Commentaire commentaire : commentaires) {
            em.remove(commentaire);
        }
        Collection<Note> notes = new ArrayList<Note>(gestionnaireNotes.getNoteByUtilisateur(utilisateur));
        for (Note note : notes) {
            em.remove(note);
        }
        em.remove(utilisateur);
    }
}
